<?php
	class TxModel extends Model{
		function addtx($addtx){
			//$pid,$rid_1,$rid_2;
			$add['time']=time();
			$add['pid']=$addtx['pid'];
			$add['uid']=$addtx['uid'];
			$add['rid_1']=$addtx['rid_1'];
			$add['rid_2']=$addtx['rid_2'];
			$add['num']=$addtx['num'];
			$this->add($add);
		}
		function allinfo(){
			$info=$this->alltx();
			foreach ($info as $key => $value) {
				$post=D('Post')->find($value['pid']);
				
				$pd=$post['pd'];
				$pid=$value['pid'];
				$title=$post['title'];
				$renum=$post['renum'];
				$num=$value['num'];//page
				$page=ceil($renum/25)-ceil($num/25)+1;
				$rid_1=D('Repost')->find($value['rid_1']);
				$rid_2=D('Repost')->find($value['rid_2']);//回复信息

				$back['pid']=$pid;
				$back['title']=$title;
				$back['pd']=$pd;
				$back['page']=$page;
				$back['rid_1']=$rid_1;
				$back['rid_2']=$rid_2;
				$back['time']=$value['time'];

				$re[]=$back;

				//$num caculate for page .Future

				//$a[]['title']="xxxx";				
			}
			return $re;
		}
		function alltx(){
			$uid=$_SESSION['uid'];
			$all=$this->where("uid='".$uid."'")->order('time desc')->select();
			return $all;//array
		}
		function unread(){
			$all=$this->alltx();
			foreach ($all as $key => $value) {
				if(!$value['is_read']){
					$un[]=$value;
				}
			}
			return $un;//array
		}
		function count(){
			return count($this->unread());
		}
		function readall(){
			$un=$this->unread();
			foreach ($un as $key => $value) {
				$this->where("tid='".$value['tid']."'")->setField("is_read",'1');
			}
		}
	}



?>